#include "checkbox.h"

CheckBox::CheckBox(QWidget* parent):QCheckBox(parent)
{

}
void CheckBox::mousePressEvent(QMouseEvent* event){
    // 改变复选框的选中状态
    if (event->button() == Qt::LeftButton) {
        setChecked(!isChecked());
        update(); // 更新显示
    }
}

void CheckBox::paintEvent(QPaintEvent *event){
    QStylePainter painter(this);
    QStyleOptionButton option;
    initStyleOption(&option);
    int width = 15;
    int height = 15;

    if (isChecked()) { // 绘制选中状态
        QPoint startPoint(0.2 * width, 0.65*height);
        QPoint centerPoint(0.4 * width, 0.8 * height);
        QPoint endPoint(0.9 * width, 0.35 * height);
        painter.setPen(QPen(QColor(68, 199, 247),1.5));
        painter.setRenderHint(QPainter::Antialiasing);
        painter.drawLine(startPoint, centerPoint);
        painter.drawLine(centerPoint, endPoint);
    }
    painter.drawControl(QStyle::CE_CheckBox, option);
}
